/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package datamodel;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Set;
import javax.persistence.*;

/**
 *
 * @author eXtreme
 */
@Entity
@javax.persistence.NamedQuery(name = "getWaitingTickets", query = "SELECT t FROM Ticket t WHERE state = 0")
public class Ticket implements Serializable {

    // -----------------------
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ticket_id")
    private Long id;
    private String title;
    @Column(columnDefinition="TEXT")
    private String content;
    private int ticket_state;
    private Timestamp created= new Timestamp((new Date()).getTime());
    private int price;
    @ManyToOne
    private Category category;
    @ManyToOne
    private SystemAdmin solvedBy;
    @ManyToOne
    private SystemCustomer createdBy;
    @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "inTicket",fetch= FetchType.EAGER)
    @OrderBy("created DESC")
    private Set<Post> hasPosts;
    // -----------------------

    public Ticket() {
    }

    public Ticket(String title, String content, Category category, SystemCustomer createdBy) {
        this.title = title;
        this.content = content;
        this.createdBy = createdBy;
        this.ticket_state = 0;
        this.price = 0;
        this.category = category;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Timestamp getCreated() {
        return created;
    }

    public void setCreated(Timestamp created) {
        this.created = created;
    }

    public SystemCustomer getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(SystemCustomer createdBy) {
        this.createdBy = createdBy;
    }

    public Set<Post> getHasPosts() {
        return hasPosts;
    }

    public void setHasPosts(Set<Post> hasPosts) {
        this.hasPosts = hasPosts;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public SystemAdmin getSolvedBy() {
        return solvedBy;
    }

    public void setSolvedBy(SystemAdmin solvedBy) {
        this.solvedBy = solvedBy;
    }

    public int getTicket_state() {
        return ticket_state;
    }

    public void setTicket_state(int ticket_state) {
        this.ticket_state = ticket_state;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (getId() != null ? getId().hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Ticket)) {
            return false;
        }
        Ticket other = (Ticket) object;
        if ((this.getId() == null && other.getId() != null) || (this.getId() != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Ticket[ id=" + getId() + " ] = " + getTitle() + " " + getContent();
    }
}
